const { createServer } = require('@modelcontextprotocol/server');
const fs = require('fs');
const path = require('path');
const config = require('../config/default.json');

// 导入工具和资源
const toolsPath = path.join(__dirname, 'tools');
const tools = fs.readdirSync(toolsPath)
  .filter(file => file.endsWith('.js'))
  .map(file => require(path.join(toolsPath, file)));

const resourcesPath = path.join(__dirname, 'resources');
const resources = fs.readdirSync(resourcesPath)
  .filter(file => file.endsWith('.js'))
  .map(file => require(path.join(resourcesPath, file)));

// 创建MCP服务器
const server = createServer({
  name: config.mcp.name,
  description: config.mcp.description,
  version: config.mcp.version,
  tools: tools,
  resources: resources,
});

// 启动服务器
server.listen(config.server.port, config.server.host, () => {
  console.log(`Cursor开发助手 MCP服务器已启动，监听 ${config.server.host}:${config.server.port}`);
  console.log('可用工具:');
  tools.forEach(tool => {
    console.log(`- ${tool.name}: ${tool.description}`);
  });
  console.log('可用资源:');
  resources.forEach(resource => {
    console.log(`- ${resource.name}: ${resource.description}`);
  });
}); 